import os,sys
from datetime import datetime,timedelta
def log_set(msg, name='my_log'):
    if 'win' in sys.platform:
        FILE_path = os.getcwd() +'\log'
        now_time = datetime.now()
        yes_date = now_time + timedelta(days=-1)
        str_now = str(now_time).split('.')[0]
        str_yes = str(yes_date).split('.')[0]
        FILE_yes = FILE_path +'\%s%s'%(name, str_yes)
        FILE_main = FILE_path +'\%s_%s'%(name, str_now)

        create_file="md %s ;echo''>%s"% (FILE_path, FILE_main[:-9])
        del_file="cd %s; ;del %s ;echo ''>%s" % (FILE_path, FILE_yes[:-9],FILE_main[:-9])
    if 'linux' in sys.platform:
        FILE_path = os.getcwd() +'/log'
        now_time = datetime.now()
        yes_date = now_time + timedelta(days=-1)
        str_now = str(now_time).split('.')[0]
        str_yes = str(yes_date).split('.')[0]
        FILE_yes = FILE_path +'/%s%s'%(name, str_yes)
        FILE_main = FILE_path +'/%s_%s'%(name, str_now)
        create_file='mkdir -p %s ;touch %s' % (FILE_path, FILE_main[:-9])
        del_file='mkdir -p %s ;rm %s ;touch %s' % (FILE_path, FILE_yes[:-9],FILE_main[:-9])
    try:

        if not os.path.exists(str(FILE_main[:-9])):
            if 'win' in sys.platform:
                for c in create_file.split(';'):
                    os.system(c)
            else:
                os.system(create_file)
        if  os.path.exists(str(FILE_yes[:-9])):
            os.system(del_file)
    except:
        pass
    print(msg)
    f = open('%s' % FILE_main[:-9], 'a+')
    f.write('[' + str(datetime.now()).split('.')[0] + ']' + msg + '\n')
    f.close()
if __name__=='__main__':
    log_set('test')
